package main

import (
	"fmt"
	"reflect"
)

type Foo struct {
	Id int
}
type Bar struct {
	Age int
}

func (this *Bar) Hello(i string) string {
	fmt.Println(i)
	return i
}

//用于保存实例化的结构体对象
var regStruct map[string]interface{}

func main() {
	str := "Bar"
	regStruct = make(map[string]interface{})
	regStruct["Foo"] = Foo{9}
	regStruct["Bar"] = Bar{5}
	if regStruct[str] != nil {
		t := reflect.ValueOf(regStruct[str]).Type()
		obj := reflect.New(t).Elem()
		for i := 0; i < obj.NumField(); i++ {
			field := obj.Field(i)
			fmt.Println(obj.Type().Field(i).Name, field.Type(), field.Interface())
		}
		testStr := "hello,world"
		parms := []reflect.Value{reflect.ValueOf(testStr)}
		reflect.New(t).MethodByName("Hello").Call(parms)
		y := reflect.ValueOf("Bar").Type()
		reflect.New(y).MethodByName("Hello").Call(parms)
	}

}

func init() {

}
